<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>IDE</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    html,
    body,
    #root {
      height: 100%;
    }
    #textarea,
    .result-warp {
      float: left;
      height: 100%;
      font-size: 18px;
    }
    #textarea {
      width: 70%;
      border: 0;
      background: #282C34;
      color: #E6DB63;
    }
    #textarea:focus {
      outline: 0;
      outline-offset: 0;
    }
    .result-warp {
      width: 30%;
      box-sizing: border-box;
      border-left: 1px solid #666;
      background: #282C34;
      color: #fff;
    }
    #run-btn {
      padding: 4px 24px;
      font-size: 18px;
    }
    #result {
      font-size: 18px;
    }
    .result-text {
      padding: 10px 0;
    }
  </style>
</head>
<body>
  <div id="root">
    <textarea id="textarea"></textarea>
    <div class="result-warp">
      <button id="run-btn">run</button>
      <div class="result-text">结果:</div>
      <div id="result"></div>
    </div>
  </div>
  <script>
    var textDom = document.getElementById('textarea')
    var resDom = document.getElementById('result')
    var btnDom = document.getElementById('run-btn')
    btnDom.addEventListener('click', function() {
      var code = textDom.value
      if (!code) {
        alert('请输入代码!')
        return
      }
      try {
        var result = new Function(code)()
        resDom.innerText = result
      } catch (error) {
        resDom.innerText = error
      }
    })
  </script>
</body>
</html>